﻿using IMES.Common.Domain.SirModel;
using IMES.Common.Dtos;
using IMES.Common.Infrastructure;
using MediatR;

namespace GlennQuigmire.API.Application.Commands
{
    public class ProductDetailHander : IRequestHandler<ProductDetailCommand, Result>
    {


        private readonly IBaseRepositorys<Product> _productRepository;

        public ProductDetailHander(IBaseRepositorys<Product> productRepository)
        {
            _productRepository = productRepository;
        }

        /// <summary>
        /// 反添商品信息
        /// </summary>
        /// <param name="request">反添商品信息请求参数</param>
        /// <param name="cancellationToken">异步取消标记</param>
        /// <returns>反添的商品信息数据</returns>
        public Task<Result> Handle(ProductDetailCommand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            var info = _productRepository.GetAll().FirstOrDefault(c => c.ProductId == request.ProductId);
            result.Data = info;
            return Task.FromResult(result);
        }
    }
}
